//
//  ZhongJianDiZhiViewController.m
//  LOU
//
//  Created by 要帅气的生活 on 15/11/7.
//  Copyright © 2015年 UNOHACHA. All rights reserved.
//

#import "ZhongJianDiZhiViewController.h"
#import "Head.h"
#import "DiZhiTableViewCell.h"
@interface ZhongJianDiZhiViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (nonatomic,strong) UITableView *ProvinceTable;
@property (nonatomic,strong) UIScrollView *CityScroll;
@property (nonatomic,strong) NSArray *array;
@property (nonatomic,retain) DiZhiTableViewCell *cell;
@end

@implementation ZhongJianDiZhiViewController
- (void)viewWillAppear:(BOOL)animated
{
    self.navigationController.navigationBar.hidden = NO;
}
- (void)viewDidLoad {
    [super viewDidLoad];
    self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemReply target:self action:@selector(fanghui)];
    self.navigationItem.title = @"地区选择";
    self.array = @[@"北京市",@"天津市",@"上海市",@"广东省",@"重庆市"];
    self.ProvinceTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, WindowWidth/3, WindowHeight-64)];
    [self.view addSubview:self.ProvinceTable];
    self.ProvinceTable.tag = 600;
    self.ProvinceTable.dataSource = self;
    self.ProvinceTable.delegate = self;
    [self scroll];
}
-(void)scroll{
    self.CityScroll = [[UIScrollView alloc] initWithFrame:CGRectMake(WindowWidth/3, 64, WindowWidth/3*2, WindowHeight-64*2)];
    [self.view addSubview:self.CityScroll];
    self.CityScroll.contentSize = CGSizeMake(WindowWidth/3*2*5, 0);
    self.CityScroll.scrollEnabled = NO;
    self.CityScroll.showsHorizontalScrollIndicator = YES;
    for (int i = 0; i < 5; i++) {
        UITableView *CityTable  = [[UITableView alloc] initWithFrame:CGRectMake(i*WindowWidth/3*2, 0,WindowWidth/3*2, WindowHeight-64) style:UITableViewStylePlain];
        [self.CityScroll addSubview:CityTable];
        CityTable.dataSource = self;
        CityTable.delegate = self;
        CityTable.tag = 700+i;
    }
}

-(NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    if (tableView.tag == 600) {
        return self.array.count;
    }else if (tableView.tag == 703){
        return 2;
    }else{
        return 1;
    }
}
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 600) {
        DiZhiTableViewCell *sheng = [tableView dequeueReusableCellWithIdentifier:@"wt"];
        if (sheng == nil) {
            sheng = [[DiZhiTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"wt"];
        }
        sheng.label.text = self.array[indexPath.row];
        sheng.label.textAlignment = 1;
        return sheng;
    }
    
    if (tableView.tag == 700) {
        self.cell = [tableView dequeueReusableCellWithIdentifier:@"wwwpot"];
        if (self.cell == nil) {
            self.cell = [[DiZhiTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"wwwpot"];
        }
        self.cell.label.text = @"北京";
        self.cell.label.textAlignment = 1;
        self.cell.label.tag = 710;
        return self.cell;
    }else if (tableView.tag == 701){
        self.cell = [tableView dequeueReusableCellWithIdentifier:@"www"];
        if (self.cell == nil) {
            self.cell = [[DiZhiTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"www"];
        }
        self.cell.label.text = @"天津";
        self.cell.label.textAlignment = 1;
        self.cell.label.tag = 711;
        return self.cell;
    }else if (tableView.tag == 702){
        self.cell = [tableView dequeueReusableCellWithIdentifier:@"wwww"];
        if (self.cell == nil) {
            self.cell = [[DiZhiTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"wwww"];
        }
        self.cell.label.text = @"上海";
        self.cell.label.textAlignment = 1;
        self.cell.label.tag = 712;
        return self.cell;
    }else if (tableView.tag == 703){
        self.cell = [tableView dequeueReusableCellWithIdentifier:@"pot"];
        if (self.cell == nil) {
            self.cell = [[DiZhiTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"pot"];
        }
        NSArray *arr= @[@"广州市",@"深圳市"];
        self.cell.label.text = arr[indexPath.row];
        self.cell.label.textAlignment = 1;
        self.cell.label.tag = 713+indexPath.row;
        return self.cell;
    }else if (tableView.tag == 704){
        self.cell = [tableView dequeueReusableCellWithIdentifier:@"wwot"];
        if (self.cell == nil) {
            self.cell = [[DiZhiTableViewCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"wwot"];
        }
        self.cell.label.text = @"重庆";
        self.cell.label.textAlignment = 1;
        self.cell.label.tag = 715;
        return self.cell;
    }else {
        return 0;
    }
}
-(void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    if (tableView.tag == 600) {
        
        self.CityScroll.contentOffset = CGPointMake(WindowWidth/3*2*indexPath.row, 0);
    }if (tableView.tag == 700) {
        self.suml([[self.view viewWithTag:710] text]);
        [self.navigationController popViewControllerAnimated:YES];
    }if (tableView.tag == 701) {
        self.suml([[self.view viewWithTag:711] text]);
        [self.navigationController popViewControllerAnimated:YES];
    }if (tableView.tag == 702) {
        self.suml([[self.view viewWithTag:712] text]);
        [self.navigationController popViewControllerAnimated:YES];
    }if (tableView.tag == 703) {
        if (indexPath.row == 0) {
            self.suml([[self.view viewWithTag:713] text]);
            [self.navigationController popViewControllerAnimated:YES];
        }else{
            self.suml([[self.view viewWithTag:714] text]);
            [self.navigationController popViewControllerAnimated:YES];
        }
    }if (tableView.tag == 704) {
        self.suml([[self.view viewWithTag:715] text]);
        [self.navigationController popViewControllerAnimated:YES];
    }
}
-(void)fanghui{
    [self.navigationController popViewControllerAnimated:YES];
    self.navigationController.navigationBarHidden = YES;
}

@end
